﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Top.Web;
using Top.Web.Api;
using Top.Web.Api.Filters;

namespace Top.PointStore.Filters
{

    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
    public class BrokerLoginAttribute : ApiFilterAttribute
    {
        public BrokerLoginAttribute()
        {
            Check = true;
        }
        public override bool AllowMultiple
        {
            get
            {
                return false;
            }
        }
        public BrokerLoginAttribute(bool check)
        {
            Check = check;
        }
        public bool Check { get; private set; }

        public override object OnActionExecuting(IWebApi api)
        {
            if (Check == false)
            {
                return null;
            }
            if (api.User != null && api.User.IsBroker)
            {
                return null;
            }
            return new WebApiException(ExceptionCode.NotLogin, "请先登录!");
        }

    }
}